<template>
  <div class="flex flex-col h-full">
    <a-card class="mt-2 flex-1">
      <BaseTable :loading="loading" column-code="00001198" :data-source="tableData" fill>
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'isuseDeposit'">
            <a-switch v-model:checked="record.isuseDeposit" @change="onSwitch(record)" />
          </template>
          <template v-if="column.dataIndex === 'isuse'">
            <a-switch v-model:checked="record.isuse" @change="onSwitch(record)" />
          </template>
          <template v-if="column.dataIndex === 'zffsmc'">
            <EditCell v-if="record.issystem">
              <a-input v-model:value="record.zffsmc" placeholder="请输入" @blur="onBlurSave(record)" />
            </EditCell>
            <div v-else>{{ record.zffsmc }}</div>
          </template>
          <template v-if="column.dataIndex === 'outorder'">
            <EditCell>
              <a-input v-model:value="record.outorder" placeholder="请输入" @blur="onBlurSave(record)" />
            </EditCell>
          </template>
        </template>
      </BaseTable>
    </a-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { message } from 'ant-design-vue'
import { post } from '@/utils/request'
// import { message } from 'ant-design-vue'

const loading = ref(false)
const tableData = ref([])

const queryList = async () => {
  loading.value = true
  const { code, data, msg } = await post('/operation/chargeStandard/getChargeTypeList', {})
  if (code !== 0) return message.error(msg)
  tableData.value = data.map((item) => {
    item.isuse = item.isuse === 0 ? true : false
    item.isuseDeposit = item.isuseDeposit === 0 ? true : false
    return item
  })
  loading.value = false
}
const onBlurSave = async (record) => {
  const { code, msg } = await post('/operation/chargeStandard/doSaveChargeType', {
    ...record,
    isuse: record.isuse ? 0 : 1,
    isuseDeposit: record.isuseDeposit ? 0 : 1
  })
  if (code !== 0) return message.error(msg)
  message.success(msg)
  queryList()
}
const onSwitch = async (record) => {
  const { code, msg } = await post('/operation/chargeStandard/doSaveChargeType', {
    id: record.id,
    isuse: record.isuse ? 0 : 1,
    isuseDeposit: record.isuseDeposit ? 0 : 1
  })
  if (code !== 0) return message.error(msg)
  message.success(msg)
  queryList()
}
onMounted(() => {
  queryList()
})
</script>

<style lang="less" scoped></style>
